layui.use(['table', 'jquery','element','layer','form','upload'], function () {
    var table = layui.table;
    var $ = layui.jquery;
    var element = layui.element;
    var layer = layui.layer;
    var form = layui.form;
    var upload = layui.upload;

    //第一个实例
    table.render({
        elem: '#table',
        height: 600,
        defaultToolbar : []
        , url: ctx + '/eng/bet/listPage'
        , page: true
        , cols: [[
            {field: 'id', title: 'ID', align: 'center',width:'5%',hide : true},
            {field: 'seq', title: '次序', align: 'center',width:'25%'},
            {field: 'amount', title: '积分数', align: 'center',width:'25%'},
            {field: 'rate', title: '权重(整数)', align: 'center',width:'25%'},
            {field: 'ops', title: '操作', width: '25%', align: 'center',toolbar: '#tool'}
        ]]
    });


    // tool
    table.on('tool(table)', function(obj){
        var data = obj.data;
        var layEvent = obj.event;
        if(layEvent === 'update'){
            update(data);
        }
    });


    // 更新数据内容
    var updateData = null;
    function update(data){
        updateData = data;
        // 弹出层
        layer.open({
            type : 1,
            title : '修改抽奖参数',
            content : $('#updateLayer'),
            btn : ['确定'],
            yes : function(index){
                $.ajax({
                    url :ctx+"/eng/bet/update?id="+updateData.id,
                    data : $('#addForm').serialize(),
                    type : 'post',
                    async : false,
                    success : function(res){
                        if(res.success){
                            layer.closeAll()
                            table.reload('table')
                        }else{
                            layer.msg(res.msg,{icon:2});
                        }
                    }
                });
            }
        });
    }
});